package algorithm;

public class leetcode_0013 {
    public int romanToInt(String s) {
        char[] num=s.toCharArray();
        int len=num.length;
        int number=0;
        for(int i=0;i<len-1;++i){
            number+=numtran(num[i]);
            if(numtran(num[i])<numtran(num[i+1])){
                number-=2*numtran(num[i]);
            }
        }
        number+=numtran(num[len-1]);
        return number;
    }
    public int numtran(char a){
        if(a=='I') return 1;
        else if(a=='V') return 5;
        else if(a=='X') return 10;
        else if(a=='L') return 50;
        else if(a=='C') return 100;
        else if(a=='D') return 500;
        else return 1000;
    }
}
